let update = require('immutability-helper');

const state1 = ['x'];
const state2 = update(state1, { $push: ['y'] }); // ['x', 'y']

console.dir(state2);


let obj = {
    a: {
        b: {
            c: 1,
        }
    }
};

console.dir(
    update(obj, {
        a: {
            b: {
                c: { '$set': '1024' }
            }
        },
    })
);

// 这里为啥需要传递一个双重数组？
// {$splice: array of arrays} for each item in arrays call splice() on the target with the parameters provided by the item.
// Note: The items in the array are applied sequentially, so the order matters.
// The indices of the target may change during the operation.
// 这里双重数组的原因 就在于 他会顺序的执行这些操作
let arr = [
    { id: 1 },
    { id: 2 },
    { id: 3 },
    { id: 4 },
];
console.dir(
    update(
        arr,
        {
            $splice: [[0, 1], [3, 0, {id: 1}]]
        }
    )
);
